//1.泛型
function join17<T, P>(first: T, second: P) {
  return `${first}${second}`;
}
join17<string, Number>("wk", 1);
//泛型的类型推断,不建议使用,加上类型更容易读代码
join17("wk", 1);
//2.泛型中数组的使用
// function myFun17<T>(params: T[]) {
function myFun17<T>(params: Array<T>) {
  return params;
}
myFun17<string>(["123", "23"]);

//3.在类中使用泛型
class SelectGirl17<T> {
  constructor(private girls: T[]) {}
  getGirl(index: number): T {
    return this.girls[index];
  }
}
const selectGirl17 = new SelectGirl17<string>(["大脚", "刘英", "晓红"]);
console.log(selectGirl17.getGirl(1));
//4.类中使用的泛型继承了接口,实例化的时候传递的参数就必须携带接口中定义的属性
interface Girl17 {
  name: string;
}
class SelectGirl171<T extends Girl17> {
  constructor(private girls: T[]) {}
  getGirl(index: number): T {
    return this.girls[index];
  }
}
const selectGirl171 = new SelectGirl171([{ name: "大脚" }, { name: "刘英" }, { name: "晓红" }]);
console.log(selectGirl171.getGirl(1));
//4.泛型约束,限制传入传出参数的类型
class SelectGirl172<T extends string | number> {
  constructor(private girls: T[]) {}
  getGirl(index: number): T {
    return this.girls[index];
  }
}
const selectGirl172 = new SelectGirl172<string>(["大脚", "刘英", "晓红"]);
console.log(selectGirl172.getGirl(1));